package com.bjqg.bjqg01.bjqg.activity.longrange.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.address.activity.AddressManagerActivity;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.ImageItem;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.AddressEventBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.FsBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MultipleBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.WallBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.BottomMenuDialog;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.JcDialog;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.CydwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.CyrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.GcmcBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.JzdwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.JzrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.SgbwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtdwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtrPhoneBeanUtils;
import com.bjqg.bjqg01.bjqg.ui.pickview.OptionsPickerView;
import com.bjqg.bjqg01.bjqg.ui.pickview.listener.CustomListener;
import com.bjqg.bjqg01.bjqg.utils.Bimp;
import com.bjqg.bjqg01.bjqg.utils.BitmapUtils;
import com.bjqg.bjqg01.bjqg.utils.GreendaoUtils;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoActivity;
import com.jph.takephoto.compress.CompressConfig;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.jph.takephoto.model.TakePhotoOptions;
import com.zhy.autolayout.AutoLinearLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/7.
 */

public class WallActivity extends TakePhotoActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.tv_jllb)
    TextView tvJllb;
    @BindView(R.id.commissioned_et_wtdw)
    AutoCompleteTextView commissionedEtWtdw;
    @BindView(R.id.et_wtr)
    AutoCompleteTextView etWtr;
    @BindView(R.id.et_wtrdh)
    AutoCompleteTextView etWtrdh;
    @BindView(R.id.commissioned_et_gcmc)
    AutoCompleteTextView commissionedEtGcmc;
    @BindView(R.id.et_sgbw)
    AutoCompleteTextView etSgbw;
    @BindView(R.id.et_qjlhntxxkxqkjy_clmc)
    TextView etQjlhntxxkxqkjyClmc;
    @BindView(R.id.et_qjlhntxxkxqkjy_dj)
    TextView etQjlhntxxkxqkjyDj;
    @BindView(R.id.et_qjlhntxxkxqkjy_pz)
    TextView etQjlhntxxkxqkjyPz;
    @BindView(R.id.et_qjlhntxxkxqkjy_gg)
    TextView etQjlhntxxkxqkjyGg;
    @BindView(R.id.et_qjlhntxxkxqkjy_yjbz)
    TextView etQjlhntxxkxqkjyYjbz;
    @BindView(R.id.et_qjlhntxxkxqkjy_qddj)
    TextView etQjlhntxxkxqkjyQddj;
    @BindView(R.id.et_qjlhntxxkxqkjy_mddj)
    TextView etQjlhntxxkxqkjyMddj;
    @BindView(R.id.et_qjlhntxxkxqkjy_sccj)
    EditText etQjlhntxxkxqkjySccj;
    @BindView(R.id.et_qjlhntxxkxqkjy_dbsl)
    TextView etQjlhntxxkxqkjyDbsl;
    @BindView(R.id.et_qjlhntxxkxqkjy_zlzms)
    EditText etQjlhntxxkxqkjyZlzms;
    @BindView(R.id.et_qjlhntxxkxqkjy_sb)
    EditText etQjlhntxxkxqkjySb;
    @BindView(R.id.et_qjlhntxxkxqkjy_lysl)
    EditText etQjlhntxxkxqkjyLysl;
    @BindView(R.id.et_qjlhntxxkxqkjy_jcxm)
    TextView etQjlhntxxkxqkjyJcxm;
    @BindView(R.id.ll_qjlhntxxkxqkjy_father)
    AutoLinearLayout llQjlhntxxkxqkjyFather;
    @BindView(R.id.et_pthntxxkxqkjy_zl)
    TextView etPthntxxkxqkjyZl;
    @BindView(R.id.et_pthntxxkxqkjy_qddj)
    TextView etPthntxxkxqkjyQddj;
    @BindView(R.id.et_pthntxxkxqkjy_gg)
    EditText etPthntxxkxqkjyGg;
    @BindView(R.id.et_pthntxxkxqkjy_cd)
    EditText etPthntxxkxqkjyCd;
    @BindView(R.id.et_pthntxxkxqkjy_dbsl)
    EditText etPthntxxkxqkjyDbsl;
    @BindView(R.id.et_pthntxxkxqkjy_mddj)
    TextView etPthntxxkxqkjyMddj;
    @BindView(R.id.et_pthntxxkxqkjy_yjbz)
    EditText etPthntxxkxqkjyYjbz;
    @BindView(R.id.et_pthntxxkxqkjy_dj)
    TextView etPthntxxkxqkjyDj;
    @BindView(R.id.et_pthntxxkxqkjy_zlzmsh)
    EditText etPthntxxkxqkjyZlzmsh;
    @BindView(R.id.et_pthntxxkxqkjy_sb)
    EditText etPthntxxkxqkjySb;
    @BindView(R.id.et_pthntxxkxqkjy_lusl)
    EditText etPthntxxkxqkjyLusl;
    @BindView(R.id.et_pthntxxkxqkjy_jcxm)
    TextView etPthntxxkxqkjyJcxm;
    @BindView(R.id.ll_pthntxxkxqkjy_father)
    AutoLinearLayout llPthntxxkxqkjyFather;
    @BindView(R.id.et_sjptdkzjy_zl)
    TextView etSjptdkzjyZl;
    @BindView(R.id.et_sjptdkzjy_qddj)
    TextView etSjptdkzjyQddj;
    @BindView(R.id.et_sjptdkzjy_pz)
    TextView etSjptdkzjyPz;
    @BindView(R.id.et_sjptdkzjy_gg)
    TextView etSjptdkzjyGg;
    @BindView(R.id.et_sjptdkzjy_mddj)
    TextView etSjptdkzjyMddj;
    @BindView(R.id.et_sjptdkzjy_yjbz)
    EditText etSjptdkzjyYjbz;
    @BindView(R.id.et_sjptdkzjy_dj)
    TextView etSjptdkzjyDj;
    @BindView(R.id.et_sjptdkzjy_scdw)
    EditText etSjptdkzjyScdw;
    @BindView(R.id.et_sjptdkzjy_dbsl)
    EditText etSjptdkzjyDbsl;
    @BindView(R.id.et_sjptdkzjy_zlzmsh)
    EditText etSjptdkzjyZlzmsh;
    @BindView(R.id.et_sjptdkzjy_sb)
    EditText etSjptdkzjySb;
    @BindView(R.id.et_sjptdkzjy_lysl)
    EditText etSjptdkzjyLysl;
    @BindView(R.id.et_sjptdkzjy_jcxm)
    TextView etSjptdkzjyJcxm;
    @BindView(R.id.ll_sjptdkzjy_father)
    AutoLinearLayout llSjptdkzjyFather;
    @BindView(R.id.et_sjkxzjy_zl)
    TextView etSjkxzjyZl;
    @BindView(R.id.et_sjkxzjy_qddj)
    TextView etSjkxzjyQddj;
    @BindView(R.id.et_sjkxzjy_pz)
    TextView etSjkxzjyPz;
    @BindView(R.id.et_sjkxzjy_gg)
    TextView etSjkxzjyGg;
    @BindView(R.id.et_sjkxzjy_mddj)
    TextView etSjkxzjyMddj;
    @BindView(R.id.et_sjkxzjy_yjbz)
    EditText etSjkxzjyYjbz;
    @BindView(R.id.et_sjkxzjy_dj)
    TextView etSjkxzjyDj;
    @BindView(R.id.et_sjkxzjy_scdw)
    EditText etSjkxzjyScdw;
    @BindView(R.id.et_sjkxzjy_dbsl)
    TextView etSjkxzjyDbsl;
    @BindView(R.id.et_sjkxzjy_zlzms)
    EditText etSjkxzjyZlzms;
    @BindView(R.id.et_sjkxzjy_sb)
    EditText etSjkxzjySb;
    @BindView(R.id.et_sjkxzjy_lysl)
    EditText etSjkxzjyLysl;
    @BindView(R.id.et_sjkxzjy_jcxm)
    TextView etSjkxzjyJcxm;
    @BindView(R.id.ll_sjkxzjy_father)
    AutoLinearLayout llSjkxzjyFather;
    @BindView(R.id.et_zyjqhntqkjy_zl)
    TextView etZyjqhntqkjyZl;
    @BindView(R.id.et_zyjqhntqkjy_qddj)
    TextView etZyjqhntqkjyQddj;
    @BindView(R.id.et_zyjqhntqkjy_gg)
    TextView etZyjqhntqkjyGg;
    @BindView(R.id.et_zyjqhntqkjy_mddj)
    TextView etZyjqhntqkjyMddj;
    @BindView(R.id.et_zyjqhntqkjy_yjbz)
    EditText etZyjqhntqkjyYjbz;
    @BindView(R.id.et_zyjqhntqkjy_dj)
    TextView etZyjqhntqkjyDj;
    @BindView(R.id.et_zyjqhntqkjy_scdw)
    EditText etZyjqhntqkjyScdw;
    @BindView(R.id.et_zyjqhntqkjy_dbsl)
    EditText etZyjqhntqkjyDbsl;
    @BindView(R.id.et_zyjqhntqkjy_zlzms)
    EditText etZyjqhntqkjyZlzms;
    @BindView(R.id.et_zyjqhntqkjy_sb)
    EditText etZyjqhntqkjySb;
    @BindView(R.id.et_zyjqhntqkjy_lysl)
    EditText etZyjqhntqkjyLysl;
    @BindView(R.id.et_zyjqhntqkjy_jcxm)
    TextView etZyjqhntqkjyJcxm;
    @BindView(R.id.ll_zyjqhntqkjy_father)
    AutoLinearLayout llZyjqhntqkjyFather;
    @BindView(R.id.et_qtz_zl)
    TextView etQtzZl;
    @BindView(R.id.et_qtz_dj)
    TextView etQtzDj;
    @BindView(R.id.et_qtz_gg)
    TextView etQtzGg;
    @BindView(R.id.et_qtz_yjbz)
    EditText etQtzYjbz;
    @BindView(R.id.et_qtz_qddj)
    TextView etQtzQddj;
    @BindView(R.id.et_qtz_mddj)
    TextView etQtzMddj;
    @BindView(R.id.et_qtz_scdw)
    EditText etQtzScdw;
    @BindView(R.id.et_qtz_dbsl)
    EditText etQtzDbsl;
    @BindView(R.id.et_qtz_zlzs)
    EditText etQtzZlzs;
    @BindView(R.id.et_qtz_sb)
    EditText etQtzSb;
    @BindView(R.id.et_qtz_lysl)
    EditText etQtzLysl;
    @BindView(R.id.et_qtz_jcxm)
    TextView etQtzJcxm;
    @BindView(R.id.ll_qtz_father)
    AutoLinearLayout llQtzFather;

    @BindView(R.id.et_cydw)
    AutoCompleteTextView etCydw;

    @BindView(R.id.et_cyr)
    AutoCompleteTextView etCyr;

    @BindView(R.id.et_jzdw)
    AutoCompleteTextView etJzdw;
    @BindView(R.id.et_jzr)
    AutoCompleteTextView etJzr;

    @BindView(R.id.ll_jzqy)
    AutoLinearLayout llJzqy;
    @BindView(R.id.et_bz)
    EditText etBz;
    @BindView(R.id.rb_zq)
    RadioButton rbZq;
    @BindView(R.id.rb_yj)
    RadioButton rbYj;
    @BindView(R.id.rg)
    RadioGroup rg;
    @BindView(R.id.et_ddh)
    EditText etDdh;
    @BindView(R.id.ll_ddh)
    AutoLinearLayout llDdh;
    @BindView(R.id.rb_bg_zq)
    RadioButton rbBgZq;
    @BindView(R.id.rb_bg_yj)
    RadioButton rbBgYj;
    @BindView(R.id.rg_bg)
    RadioGroup rgBg;
    @BindView(R.id.tv_xzdz)
    TextView tvXzdz;
    @BindView(R.id.tv_xm)
    TextView tvXm;
    @BindView(R.id.tv_lxdh)
    TextView tvLxdh;
    @BindView(R.id.tv_yjdz)
    TextView tvYjdz;
    @BindView(R.id.ll_yj_father)
    AutoLinearLayout llYjFather;
    @BindView(R.id.btn_send)
    Button btnSend;
    @BindView(R.id.et_qjlhntxxkxqkjy_zj)
    TextView etZj;


    List<WallBean> walllist = new ArrayList<>();
    List<String> name = new ArrayList<>();
    OptionsPickerView pvFenLei;
    @BindView(R.id.tv_ywtbh)
    TextView tvYwtbh;
    @BindView(R.id.et_bgfs)
    TextView etBgfs;
    @BindView(R.id.iv_wtd)
    ImageView ivWtd;

    private SimpleDateFormat format;
    private String PHOTO_FILE_NAME;
    private StringBuffer sb = new StringBuffer();
    private BottomMenuDialog mButtomMenuDialog;
    private File dir;
    private boolean isFirstIn = true;//记录是否是刚进入页面
    JcDialog.Builde builde;
    OptionsPickerView pvFs;
    List<FsBean> list1 = new ArrayList<>();
    List<String> lvname = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wall);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        initdata();
        initfelei();
        initfs();
    }

    private void initdata() {
        dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/PhotoPickTemp");
        if (!dir.exists()) {
            dir.mkdirs();
        }

        format = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.CHINA);

        tvTopTitleDrawer.setText(getIntent().getStringExtra("name"));
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);
        tvJllb.setText("轻集料混凝体小型空心砌块检验");
        walllist.add(new WallBean("轻集料混凝体小型空心砌块检验", "1"));
        walllist.add(new WallBean("普通混凝土小型空心砌块检验", "2"));
        walllist.add(new WallBean("烧结普通（多孔）砖检验", "3"));
        walllist.add(new WallBean("烧结空心砖检验", "4"));
        walllist.add(new WallBean("蒸压加气混凝土砌块检验", "5"));
        walllist.add(new WallBean("其他转", "6"));

        for (int i = 0; i < walllist.size(); i++) {
            name.add(walllist.get(i).getName());
        }


        list1.add(new FsBean("1份  ¥0", "1"));
        list1.add(new FsBean("2份  ¥10", "2"));
        list1.add(new FsBean("3份  ¥20", "3"));
        list1.add(new FsBean("4份  ¥30", "4"));
        list1.add(new FsBean("5份  ¥40", "5"));
        list1.add(new FsBean("6份  ¥50", "6"));
        list1.add(new FsBean("7份  ¥60", "7"));
        list1.add(new FsBean("8份  ¥70", "8"));
        list1.add(new FsBean("9份  ¥80", "9"));
        list1.add(new FsBean("10份  ¥90", "10"));

        for (int i = 0; i < list1.size(); i++) {
            lvname.add(list1.get(i).getName());
        }


        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtdwBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "wtdw.db")));
        commissionedEtWtdw.setAdapter(adapter);


        //委托人
        ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtrBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "wtr.db")));
        etWtr.setAdapter(adapter2);

        //委托人电话
        ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtrPhoneBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "wtrdh.db")));
        etWtrdh.setAdapter(adapter3);

        //工程名称
        ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, GcmcBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "gcmc.db")));
        commissionedEtGcmc.setAdapter(adapter4);

        //施工部位
        ArrayAdapter<String> adapter5 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, SgbwBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "sgbw.db")));
        etSgbw.setAdapter(adapter5);

        //抽样单位
        ArrayAdapter<String> adapter6 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, CydwBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "cydw.db")));
        etCydw.setAdapter(adapter6);

        //抽样人
        ArrayAdapter<String> adapter7 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, CyrBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "cyr.db")));
        etCyr.setAdapter(adapter7);

        //见证单位
        ArrayAdapter<String> adapter8 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, JzdwBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "jzdw.db")));
        etJzdw.setAdapter(adapter8);

        //见证人
        ArrayAdapter<String> adapter9 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, JzrBeanUtils.listEName(GreendaoUtils.getDaoSession(WallActivity.this, "jzr.db")));
        etJzr.setAdapter(adapter9);
        Callphone();
    }

    @OnClick({R.id.back, R.id.tv_jllb, R.id.btn_send, R.id.et_qjlhntxxkxqkjy_jcxm, R.id.et_pthntxxkxqkjy_jcxm, R.id.et_sjptdkzjy_jcxm,
            R.id.rb_zq, R.id.rb_yj, R.id.rb_bg_zq, R.id.rb_bg_yj, R.id.et_sjkxzjy_jcxm, R.id.et_zyjqhntqkjy_jcxm, R.id.et_qtz_jcxm,
            R.id.tv_xzdz, R.id.iv_wtd, R.id.et_bgfs})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.tv_jllb:
                pvFenLei.show();
                break;
            case R.id.btn_send:
                Toast.makeText(this, "保存", Toast.LENGTH_SHORT).show();
                WtdwBeanUtils.insertdata(commissionedEtWtdw.getText().toString());
                WtrBeanUtils.insertdata(etWtr.getText().toString());
                WtrPhoneBeanUtils.insertdata(etWtrdh.getText().toString());
                SgbwBeanUtils.insertdata(etSgbw.getText().toString());
                GcmcBeanUtils.insertdata(commissionedEtGcmc.getText().toString());
                CydwBeanUtils.insertdata(etCydw.getText().toString());
                CyrBeanUtils.insertdata(etCyr.getText().toString());
                JzdwBeanUtils.insertdata(etJzdw.getText().toString());
                JzrBeanUtils.insertdata(etJzr.getText().toString());
                finish();
                break;
            case R.id.rb_zq://样品送达方式 自送
                llDdh.setVisibility(View.GONE);
                etDdh.setText("");
                break;
            case R.id.rb_yj://邮寄
                llDdh.setVisibility(View.VISIBLE);
                break;
            case R.id.rb_bg_zq://报告发放方式 自取
                tvXzdz.setVisibility(View.GONE);
                llYjFather.setVisibility(View.GONE);
                tvXm.setText("");
                tvLxdh.setText("");
                tvYjdz.setText("");
                break;
            case R.id.rb_bg_yj:
                tvXzdz.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_xzdz://选择地址
                Intent toaddress = new Intent(WallActivity.this, AddressManagerActivity.class);
                toaddress.putExtra("finish", "yes");
                startActivity(toaddress);
                break;
            case R.id.et_qjlhntxxkxqkjy_jcxm:
                if (etQjlhntxxkxqkjyYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_pthntxxkxqkjy_jcxm:
                if (etPthntxxkxqkjyYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_sjptdkzjy_jcxm:
                if (etSjptdkzjyYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_sjkxzjy_jcxm:
                if (etSjkxzjyYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_zyjqhntqkjy_jcxm:
                if (etZyjqhntqkjyYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_qtz_jcxm:
                if (etQtzYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }

                break;
            case R.id.iv_wtd:
                showDialog2(view, getTakePhoto());
                break;
            case R.id.et_bgfs:
                pvFs.show();
                break;
        }
    }


    //品种分类
    private void initfelei() {
        /**
         * @description
         *
         * 注意事项：
         * 自定义布局中，id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有，否则会报空指针。
         * 具体可参考demo 里面的两个自定义layout布局。
         */

        pvFenLei = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String tx = walllist.get(options1).getName();
                tvJllb.setText(tx);

                switch (walllist.get(options1).getId()) {
                    case "1":
                        initvisibly();
                        llQjlhntxxkxqkjyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "2":
                        initvisibly();
                        llPthntxxkxqkjyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "3":
                        initvisibly();
                        llSjptdkzjyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "4":
                        initvisibly();
                        llSjkxzjyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "5":
                        initvisibly();
                        llZyjqhntqkjyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "6":
                        initvisibly();
                        llQtzFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                }


            }
        }).setLayoutRes(R.layout.material_item, new CustomListener() {
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFenLei.returnData();
                        pvFenLei.dismiss();

                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFenLei.dismiss();
                    }
                });
            }
        })
                .isDialog(false)
                .build();

        pvFenLei.setPicker(name);//添加数据
    }


    private void initvisibly() {
        llQjlhntxxkxqkjyFather.setVisibility(View.GONE);
        llPthntxxkxqkjyFather.setVisibility(View.GONE);
        llSjptdkzjyFather.setVisibility(View.GONE);
        llSjkxzjyFather.setVisibility(View.GONE);
        llZyjqhntqkjyFather.setVisibility(View.GONE);
        llQtzFather.setVisibility(View.GONE);
    }

    private void initclear() {

        etQjlhntxxkxqkjyClmc.setText("");
        etQjlhntxxkxqkjyDj.setText("");
        etQjlhntxxkxqkjyPz.setText("");
        etQjlhntxxkxqkjyGg.setText("");
        etQjlhntxxkxqkjyYjbz.setText("");
        etQjlhntxxkxqkjyQddj.setText("");
        etQjlhntxxkxqkjyMddj.setText("");
        etQjlhntxxkxqkjySccj.setText("");
        etQjlhntxxkxqkjyDbsl.setText("");
        etQjlhntxxkxqkjyZlzms.setText("");
        etQjlhntxxkxqkjySb.setText("");
        etQjlhntxxkxqkjyLysl.setText("");
        etQjlhntxxkxqkjyJcxm.setText("");

        etPthntxxkxqkjyZl.setText("");
        etPthntxxkxqkjyQddj.setText("");
        etPthntxxkxqkjyGg.setText("");
        etPthntxxkxqkjyCd.setText("");
        etPthntxxkxqkjyDbsl.setText("");
        etPthntxxkxqkjyMddj.setText("");
        etPthntxxkxqkjyYjbz.setText("");
        etPthntxxkxqkjyDj.setText("");
        etPthntxxkxqkjyZlzmsh.setText("");
        etPthntxxkxqkjySb.setText("");
        etPthntxxkxqkjyLusl.setText("");
        etPthntxxkxqkjyJcxm.setText("");

        etSjptdkzjyZl.setText("");
        etSjptdkzjyQddj.setText("");
        etSjptdkzjyPz.setText("");
        etSjptdkzjyGg.setText("");
        etSjptdkzjyMddj.setText("");
        etSjptdkzjyYjbz.setText("");
        etSjptdkzjyDj.setText("");
        etSjptdkzjyScdw.setText("");
        etSjptdkzjyDbsl.setText("");
        etSjptdkzjyZlzmsh.setText("");
        etSjptdkzjySb.setText("");
        etSjptdkzjyLysl.setText("");
        etSjptdkzjyJcxm.setText("");

        etSjkxzjyZl.setText("");
        etSjkxzjyQddj.setText("");
        etSjkxzjyPz.setText("");
        etSjkxzjyGg.setText("");
        etSjkxzjyMddj.setText("");
        etSjkxzjyYjbz.setText("");
        etSjkxzjyDj.setText("");
        etSjkxzjyScdw.setText("");
        etSjkxzjyDbsl.setText("");
        etSjkxzjyZlzms.setText("");
        etSjkxzjySb.setText("");
        etSjkxzjyLysl.setText("");
        etSjkxzjyJcxm.setText("");

        etZyjqhntqkjyZl.setText("");
        etZyjqhntqkjyQddj.setText("");
        etZyjqhntqkjyGg.setText("");
        etZyjqhntqkjyMddj.setText("");
        etZyjqhntqkjyYjbz.setText("");
        etZyjqhntqkjyDj.setText("");
        etZyjqhntqkjyScdw.setText("");
        etZyjqhntqkjyDbsl.setText("");
        etZyjqhntqkjyZlzms.setText("");
        etZyjqhntqkjySb.setText("");
        etZyjqhntqkjyLysl.setText("");
        etZyjqhntqkjyJcxm.setText("");

        etQtzZl.setText("");
        etQtzDj.setText("");
        etQtzGg.setText("");
        etQtzYjbz.setText("");
        etQtzQddj.setText("");
        etQtzMddj.setText("");
        etQtzScdw.setText("");
        etQtzDbsl.setText("");
        etQtzZlzs.setText("");
        etQtzSb.setText("");
        etQtzLysl.setText("");
        etQtzJcxm.setText("");
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXX(AddressEventBean messageEvent) {
        if (messageEvent.getId().equals("address")) {
            tvXzdz.setVisibility(View.GONE);
            llYjFather.setVisibility(View.VISIBLE);
            tvXm.setText(messageEvent.getName());
            tvLxdh.setText(messageEvent.getPhone());
            tvYjdz.setText(messageEvent.getAddress());
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXl(List<MultipleBean> multiplist) {
        int price = 0;
        for (int i = 0; i < multiplist.size(); i++) {
            sb.append(multiplist.get(i).getName() + ",");
            price += multiplist.get(i).getPrice();
        }
        etZj.setText("¥" + price);
        if (tvJllb.getText().toString().equals("轻集料混凝体小型空心砌块检验")) {
            etQjlhntxxkxqkjyJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (tvJllb.getText().toString().equals("普通混凝土小型空心砌块检验")) {
            etPthntxxkxqkjyJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (tvJllb.getText().toString().equals("烧结普通（多孔）砖检验")) {
            etSjptdkzjyJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (tvJllb.getText().toString().equals("烧结空心砖检验")) {
            etSjkxzjyJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (tvJllb.getText().toString().equals("蒸压加气混凝土砌块检验")) {
            etZyjqhntqkjyJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (tvJllb.getText().toString().equals("其他转")) {
            etQtzJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    /**
     * 选择相册照片或者拍照
     */
    private void showDialog2(View view, final TakePhoto takePhoto) {
        mButtomMenuDialog = new BottomMenuDialog.Builder(this)
                .setShadow(true)
                .addMenu("从手机相册选择", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mButtomMenuDialog.dismiss();
                        selectPhoto(takePhoto);
                    }
                }).addMenu("拍照", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mButtomMenuDialog.dismiss();
                        PHOTO_FILE_NAME = format.format(new Date()) + ".jpg";//指定拍摄图片时 返回的文件名
                        File photo = new File(dir, PHOTO_FILE_NAME);
                        Uri uri = Uri.fromFile(photo);
                        Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//拍摄图片
                        intent2.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
                        intent2.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                        startActivityForResult(intent2, 201);
                    }
                }).setCancelListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mButtomMenuDialog.dismiss();
                    }
                })
                .create();
        mButtomMenuDialog.show();
    }

    /**
     * 选择本地图片的照片
     */
    private void selectPhoto(TakePhoto takePhoto) {
        File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
        Uri imageUri = Uri.fromFile(file);
        configCompress(takePhoto);
        configTakePhotoOption(takePhoto);
        takePhoto.onPickMultiple(1);
    }

    private void configCompress(TakePhoto takePhoto) {
        CompressConfig config;
        config = new CompressConfig.Builder()
                .setMaxSize(200 * 1024)
                .create();

        takePhoto.onEnableCompress(config, true);
    }

    private void configTakePhotoOption(TakePhoto takePhoto) {
        TakePhotoOptions.Builder builder = new TakePhotoOptions.Builder();
        builder.setWithOwnGallery(true);
        builder.setCorrectImage(true);
        takePhoto.setTakePhotoOptions(builder.create());

    }


    /**
     * 选择照片、拍摄视频或者拍摄照片的返回结果
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 通过相机拍照并发送
         * */
        if (requestCode == 201) {
            if (resultCode == RESULT_OK) {
                isFirstIn = false;
                File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/PhotoPickTemp/" + PHOTO_FILE_NAME);
                Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);//刷新系统媒体库
                scanIntent.setData(Uri.fromFile(new File(file.getAbsolutePath())));
                sendBroadcast(scanIntent);//发送广播 刷新当前拍摄的图片 添加到系统媒体库
                int angle = BitmapUtils.readPictureDegree(file.getAbsolutePath());
                Bitmap bitmap = BitmapUtils.compressImage(angle, BitmapUtils.decodeUri(WallActivity.this, Uri.fromFile(new File(file.getAbsolutePath())), 720, 1280), file.getAbsolutePath());
                ImageItem takePhoto = new ImageItem();
                takePhoto.setBitmap(bitmap);
                takePhoto.setImagePath(file.getAbsolutePath());
                if (Bimp.tempSelectBitmap.size() > 0)
                    Bimp.tempSelectBitmap.clear();

                Bimp.tempSelectBitmap.add(takePhoto);

                if (Bimp.tempSelectBitmap.size() > 0) {
                    ivWtd.setImageBitmap(Bimp.tempSelectBitmap.get(0).getBitmap());
                } else {
                    ivWtd.setImageResource(R.mipmap.a_dajiahao);
                }
            } else {
                if (isFirstIn) {
                    finish();
                }
            }
        }
    }

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        isFirstIn = false;
        showImg(result.getImages());
    }

    private void showImg(ArrayList<TImage> images) {
        if (Bimp.tempSelectBitmap.size() > 0)
            Bimp.tempSelectBitmap.clear();
        for (int i = 0; i < images.size(); i++) {
            ImageItem takePhoto = new ImageItem();
            takePhoto.setBitmap(BitmapUtils.decodeUri(WallActivity.this, Uri.fromFile(new File(images.get(i).getCompressPath())), 720, 1280));
            takePhoto.setImagePath(images.get(i).getCompressPath());
            Bimp.tempSelectBitmap.add(takePhoto);
        }
        if (Bimp.tempSelectBitmap.size() > 0) {
            ivWtd.setImageBitmap(Bimp.tempSelectBitmap.get(0).getBitmap());
        } else {
            ivWtd.setImageResource(R.mipmap.a_dajiahao);
        }
    }


    private void Callphone() {
        builde = new JcDialog.Builde(this);
        builde.setCloseListener(new DialogInterface.OnClickListener() {//确定
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_CALL);
                Uri data = Uri.parse("tel:" + "02223382753");
                intent.setData(data);
                startActivity(intent);

            }
        });
        builde.setConfireListener(new DialogInterface.OnClickListener() {//取消
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }


    private void initfs() {
        pvFs = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String tx = list1.get(options1).getName();
                etBgfs.setText(tx);

            }
        }).setLayoutRes(R.layout.material_item, new CustomListener() {
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFs.returnData();
                        pvFs.dismiss();

                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFs.dismiss();
                    }
                });
            }
        })
                .isDialog(false)
                .build();

        pvFs.setPicker(lvname);//添加数据
    }
}
